package com.myblog.demo.common;

import com.myblog.demo.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 获取 Session 中的当前用户信息
 */
public class UserSessionTools {
    public static UserInfo getLoginUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        Object userObj = null;
        if (session != null && (userObj = session.getAttribute(ApplicationVariable.SESSION_KEY_USERINFO)) != null) {
            return (UserInfo) userObj;
        }
        return null;
    }
}
